package 二叉树;


/**
 * https://leetcode.cn/problems/symmetric-tree/?favorite=2cktkvj
 *
 * 前序遍历，这一题的关键是怎样是对称二叉树的遍历
 *
 * 这一题就是分解子问题
 */
public class _101_对称二叉树 {

    public boolean isSymmetric(TreeNode root) {
        if (root == null) return true;

        return dfs(root.left, root.right);
    }


    public boolean dfs(TreeNode left, TreeNode right) {
        if (left == null && right == null) return true;
        if (left == null || right == null) return false;

        if (left.val != right.val) return false;

        return dfs(left.left, right.right) && dfs(left.right, right.left);
    }
}
